package com.WheresMyCar1;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;

public class SplashActivity extends Activity {

	private final int DURACAO_DA_TELA = 500;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// setTitle("Take me to my car");
		setContentView(R.layout.tela_de_abertura);

		if (disponibilidadeDoGPS() && disponibilidadeDaRede()) {
			new Handler().postDelayed(new Runnable() {
				@Override
				public void run() {
					Intent minhaAcao = new Intent(SplashActivity.this,
							Mapa.class);
					SplashActivity.this.startActivity(minhaAcao);
					SplashActivity.this.finish();

				}
			}, DURACAO_DA_TELA);

		} else if (!disponibilidadeDaRede()) {
			Intent semConexao = new Intent(this, SemConexao.class);
			startActivity(semConexao);

			this.finish();

		} else {
			Intent semGPS = new Intent(this, SemGPS.class);
			startActivity(semGPS);

			this.finish();

		}

	}

	private boolean disponibilidadeDaRede() {
		ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo rede = connectivityManager.getActiveNetworkInfo();
		return rede != null;
	}

	private boolean disponibilidadeDoGPS() {
		LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
	}

}